<template>
  <div>
<h1>用户注册页面</h1>
<table>
  <tr>
    <td>账号：</td>
    <td><input type="text" v-model="state.ZhangHao"></td>
  </tr>
  <tr>
    <td>密码：</td>
    <td><input type="password" v-model="state.MiMa"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="注册" @click="zhe"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const route=useRoute()
const router=useRouter()

let data=reactive({
  state:{
    ZhangHao:'',
    MiMa:''
  }
})

let {state}=toRefs(data)

const zhe=()=>{

  if(state.value.ZhangHao==""){
    alert('账号不能为空');
    return;
  }
  if(state.value.MiMa==""){
    alert('密码不能为空');
    return;
  }

  axios({
    url:'/api/User/PostZhuCe',
    method:'post',
    data:state.value
  })
  .then(res=>{
    if(res.data.data==-1){
      alert('该用户已存在');
      return;
    }
    else if(res.data.data>0){
      alert('注册成功');
      router.push('/denglu');
    }
    else{
      alert('注册失败');
    }
  })
  .catch(err=>{
    console.log(err);
  })
}
</script>

<style scoped>

</style>